1. /* sdodiv.cpp by K.Tsuru */
  2. // function ID = 333 DRADIX
  3. /************************************
  4. SDouble class
  5. It provides the division operator/().
  6. it returns m/n.
  7. *************************************/
  8. #ifndef SN_H
  9. #include "sn.h"
  10. #endif
  11. static const char* func = "SD /";
  12. SDouble operator/(const SDouble& m, const SDouble& n){
  13. if((m.Type() != m.REAL)||(n.Type() != n.REAL)){
  14. m.SetError(m.RADIX_ERR, func, 333);
  15. }
  16. if( n.Sign(333) == 0 ) m.SetError(m.DIVIDED_BY_ZERO, func, 333);
  17. if( m.Sign(333) == 0 ) return 0.0;
  18. if(&m == &n) return 1.0; // m/m
  19. //It checks the overflow error.
  20. double dExp = (double)m.RdxExp()-(double)n.RdxExp();
  21. if(fabs(dExp) >= DRADIX_EXP_MAX){
  22. if(dExp > 0) m.SetError(m.OVERFLOW_ERR,func,333);
  23. else m.SetError(m.UNDERFLOW_ERR,func,333);
  24. }
  25. /*
  26. When the divisor "n" can be expressed in the form n=N*10^e (|N|<m.SlOpMaxvalue())
  27. the division becomes as m/n = (m/N)*10^(-e).If the exponent "e" has a factor four
  28. (the power of DRADIX=10000),the multiplication by 10^(-e) can be done by the
  29. moving of figures(fixed point) or the changing of exponent(floating point).
  30. exsample : m/1.3=10000*(m/13000)
  31. Using this procedure it becomes several ten times faster if the above conversion
  32. is possible.
  33. */
  34. long N, e;
  35. if( n.ConvTolongExp(&N, &e) ){ //It can be convert into n=N*10^e?
  36. SDouble r;
  37. ulong p = (ulong)labs(N);
  38. if(p != 1) r = DsDiv(m, p); // r = m/|N|
  39. else r = m;
  40. //In the fixed point mode it maybe become r=0.
  41. if( r.Sign(333) ){
  42. r.SetSign(m.Sign()*n.Sign());
  43. if(e) r.MultPow10(-e); // r = m*10^(-e)/|N| = m/|n|
  44. }
  45. return r;
  46. }
  47. return m*DReciprocal(n); // m*(1/n)
  48. }

sdodiv.cpp : last modifiled at 2015/11/25 20:17:06(1,678 bytes)
created at 2017/10/07 10:21:14
The creation time of this html file is 2017/10/07 10:30:03 (Sat Oct 07 10:30:03 2017).